﻿using BLL.ViewModel;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public partial class DataContext
    {
       
        public List<CongNo> GetListCongNo()
        {
           return db.CongNoes.ToList();
        }
        public CongNo GetCongNoById(Guid id)
        {
            return db.CongNoes.Find(id);
        }
        public bool DeleteCongNo(Guid id)
        {
            try
            {
                var user = db.CongNoes.Find(id);
                db.CongNoes.Remove(user);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public bool DeleteAllCongNo(Guid id)
        {
            try
            {
              
                var product = db.CongNoes.Find(id);
                db.CongNoes.Remove(product);
                db.SaveChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public void InsertCongNo(CongNo cthd)
        {
            db.Entry(cthd).State = EntityState.Added;
            db.SaveChanges();
        }


        //public bool UpdateCongNo(CongNo cthd)
        //{
        //    try
        //    {
        //        db.Entry(cthd).State = EntityState.Modified;
        //        db.SaveChanges();
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {

        //        return false;
        //    }

        //}


        public void UpdateCongNo(CongNo cthd)
        {
            db.Entry(cthd).State = EntityState.Modified;
            db.SaveChanges();

        }
        //Dropdowlist
        public void DropdownlistMasp()
        {
            DorSanpham spham1 = new DorSanpham();
            spham1.Sanpham = db.SanPhams
                .Select(menu => new SelectListItem
                {
                    Value = menu.MaSP.ToString(),
                    Text = menu.TenSP

                }).ToList();
            spham1.Sanpham.Insert(0, new SelectListItem
            {
                Value = "-1",
                Text = "Chọn Sản Phẩm"

            });
            spham1.Giasanpham = new List<SelectListItem>();
        }
    }
}
